//
//  WJProgressHUD.swift
//  PDFSign
//
//  Created by 李永彬 on 2025/9/22.
//

import UIKit
import SVProgressHUD

let maximumDismissTimeInterval = 3.0
/// SVProgressHUD工具类封装
class WJProgressHUD: NSObject {
    
    /// 配置SVProgressHUD的全局样式
    class func configure() {
        // 设置最小显示时间(防止一闪而过)
        SVProgressHUD.setMinimumDismissTimeInterval(3.0)
        // 设置最大显示时间
        SVProgressHUD.setMaximumDismissTimeInterval(maximumDismissTimeInterval)
        // 设置背景色
        SVProgressHUD.setBackgroundColor(UIColor(white: 0, alpha: 0.7))
        // 设置前景色(指示器和文字颜色)
        SVProgressHUD.setForegroundColor(.white)
        // 设置文字字体
        SVProgressHUD.setFont(UIFont.systemFont(ofSize: 16))
        // 设置指示器样式
        SVProgressHUD.setDefaultStyle(.dark)
        // 设置弹窗的偏移量
        SVProgressHUD.setOffsetFromCenter(UIOffset(horizontal: 0, vertical: -50))
    }
    
    /// 显示加载中(无文字)
    class func showLoading() {
        SVProgressHUD.show()
    }
    
    /// 显示加载中(有文字)
    /// - Parameter message: 加载提示文字
    class func showLoading(with message: String) {
        SVProgressHUD.show(withStatus: message)
    }
    
    /// 显示成功提示
    /// - Parameter message: 成功提示文字
    class func showSuccess(with message: String) {
        SVProgressHUD.setImageViewSize(.zero)
        SVProgressHUD.show(UIImage(), status: message)
//        SVProgressHUD.dismiss(withDelay: maximumDismissTimeInterval)
    }
    
    /// 显示错误提示
    /// - Parameter message: 错误提示文字
    class func showError(with message: String) {
        SVProgressHUD.setImageViewSize(.zero)
        SVProgressHUD.show(UIImage(), status: message)
//        SVProgressHUD.dismiss(withDelay: maximumDismissTimeInterval)
    }
    
    /// 显示信息提示
    /// - Parameter message: 信息提示文字
    class func showInfo(with message: String) {
        SVProgressHUD.setImageViewSize(.zero)
        SVProgressHUD.show(UIImage(), status: message)
//        SVProgressHUD.dismiss(withDelay: maximumDismissTimeInterval)
    }
    
    /// 显示进度
    /// - Parameters:
    ///   - progress: 进度值(0-1)
    ///   - message: 进度提示文字
    class func showProgress(_ progress: CGFloat, message: String? = nil) {
        if let message = message {
            SVProgressHUD.showProgress(Float(progress), status: message)
        } else {
            SVProgressHUD.showProgress(Float(progress))
        }
    }
    
    /// 隐藏提示
    class func dismiss() {
        SVProgressHUD.dismiss()
    }
    
    /// 延迟隐藏提示
    /// - Parameter delay: 延迟时间(秒)
    class func dismiss(withDelay delay: TimeInterval) {
        SVProgressHUD.dismiss(withDelay: delay)
    }
}
